﻿using Admin.Repository.Roles;
using Admin.Roles;
using Admin.Service.UserInfos.DTO;
using BLL.UserInfos.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin.Service.Roles
{
    public class RoleService : IRoleService
    {
        private readonly IRoleRepository roleRepository;

        public RoleService(IRoleRepository roleRepository)
        {
            this.roleRepository = roleRepository;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public Role Create(Role role)
        {
            return roleRepository.Create(role);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            return roleRepository.Delete(id);
        }

        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public int DeleteList(int[] ids)
        {
            return roleRepository.Delete(ids);
        }

        /// <summary>
        /// 根据id查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Role GetRoleId(int id)
        {
            return roleRepository.QueryId(id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        public int Update(Role role)
        {
            roleRepository.Update(role);
            return 1;
        }

        /// <summary>
        /// 查询角色全部信息
        /// </summary>
        /// <returns></returns>        
        public List<Role> GetRoles(string rolename)
        {
            //查询全部信息
            var list = roleRepository.Queryable();

            //角色名称查询
            if (!string.IsNullOrEmpty(rolename))
            {
                list = list.Where(x => x.RoleName.Contains(rolename));
            }

            return list.ToList();
        }
    }
}
